//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package weaver.interfaces.expense.action.zcpz;

import weaver.conn.RecordSet;
import weaver.general.BaseBean;
import weaver.general.Util;
import weaver.interfaces.util.ExpenseCompare;
import weaver.interfaces.util.ExpenseCompareUtil;
import weaver.interfaces.util.ExpenseInfoUtil;
import weaver.interfaces.workflow.action.Action;
import weaver.soa.workflow.request.RequestInfo;

public class ZCPZ_ExpenseAction extends BaseBean implements Action {
    public ZCPZ_ExpenseAction() {

    }

    public String execute(RequestInfo requestInfo) {
        try {
            String workflowid = requestInfo.getWorkflowid();
            String requestid = requestInfo.getRequestid();
            this.writeLog("进入ZCPZ_ExpenseAction-----------" + requestid);
            RecordSet rs = new RecordSet();
            rs.executeSql("select formid from workflow_base where id = " + workflowid);
            rs.next();
            String formid = rs.getString("formid");
            String formtable = "formtable_main_" + formid.replaceAll("-", "");
            String iskt = "0";
            String ccode = "";
            double amount = 0.0D;
            String cexpenseitemcode = "";
            String citemcode = "";
            String ly = "";
            String iyear = "";
            rs.execute("select id,ks,zcxm,xm,pjje,ly,sqrq,kthxin,liucheng from " + formtable + " where requestid=" + requestid);
            rs.next();
            ExpenseInfoUtil expenseInfoUtil = new ExpenseInfoUtil();
            ccode = expenseInfoUtil.getKsbm(Util.null2String(rs.getString("ks")));
            amount = Util.getDoubleValue(rs.getString("pjje").replace(",", ""), 0.0D);
            citemcode = Util.null2String(rs.getString("xm"));
            cexpenseitemcode = Util.null2String(rs.getString("zcxm"));
            String kth = Util.null2String(rs.getString("kthxin"));
            ly = Util.null2String(rs.getString("ly"));
            iyear = Util.null2String(rs.getString("sqrq")).substring(0, 4);
            String xglc = Util.null2String(rs.getString("xglc"));
            if("".equals(xglc)) {
                ExpenseCompareUtil expenseCompareUtil = new ExpenseCompare();
                if("0".equals(ly) || "6".equals(ly)) {
                    iskt = "1";
                    if(!expenseCompareUtil.compareExpense2(workflowid, cexpenseitemcode, kth, amount, iyear)) {
                        requestInfo.getRequestManager().setMessageid("1111111111");
                        requestInfo.getRequestManager().setMessagecontent("课题号:" + kth + " ,支出项目:" + expenseInfoUtil.getCItemName(cexpenseitemcode) + "的预算不足");
                        return "1";
                    }
                }

                if("3".equals(ly) && !expenseCompareUtil.compareExpense5(workflowid, ccode, cexpenseitemcode, amount, iyear)) {
                    requestInfo.getRequestManager().setMessageid("1111111111");
                    requestInfo.getRequestManager().setMessagecontent("科室:" + expenseInfoUtil.getCname(ccode) + ",支出项目:" + expenseInfoUtil.getCItemName(cexpenseitemcode) + ",的预算不足");
                    return "1";
                }

                if("1".equals(ly)) {
                    new BaseBean().writeLog("======财政拨款预算查询======");
                    iskt = "1";
                    //不知道这里为什么写死为0313 ，0313为设备费
//                    cexpenseitemcode = "0313";
                    if(!expenseCompareUtil.compareExpense3(workflowid,cexpenseitemcode, kth, amount, iyear)) {
                        requestInfo.getRequestManager().setMessageid("11111111121");
                        requestInfo.getRequestManager().setMessagecontent("课题号:" + kth + "，支出项目："+ expenseInfoUtil.getCItemName(cexpenseitemcode)  +"的预算不足");
                        return "1";
                    }
                }

                //因为教育经费是非课题，不跟centitycode挂钩，但是centitycode也不是空
                if("2".equals(ly)){
                    iskt = "2";
                }

                //教育经费预算校验
                if("2".equals(ly) && !expenseCompareUtil.compareExpense4(workflowid, cexpenseitemcode, amount, iyear)) {
                   
                    requestInfo.getRequestManager().setMessageid("1111111111");
                    requestInfo.getRequestManager().setMessagecontent("支出项目:" + cexpenseitemcode + "的预算不足");
                    return "1";
                }

            //扣除预算前先计算汇率
            amount = expenseInfoUtil.huilvjisuan(requestid,formtable);
            if(!"5".equals(ly) && !expenseInfoUtil.subtractExpense(workflowid, ccode, cexpenseitemcode, citemcode, kth, amount, iyear, iskt)) {
                requestInfo.getRequestManager().setMessageid("1111111111");
                requestInfo.getRequestManager().setMessagecontent("预算更新失败");
                return "1";
            }
        }

        return "1";
    } catch (Exception var19) {
        requestInfo.getRequestManager().setMessageid("1111111111");
        requestInfo.getRequestManager().setMessagecontent(var19.getMessage());
        return "1";
        }
    }
}
